package com.sqly.doc.base;

import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.widget.TextView;


/**
 * Created by 袁从斌 on 2019-06-13.
 */
public class BaseHolder extends RecyclerView.ViewHolder {
	private final SparseArray<View> mViews;
	private final View mConvertView;
	private Context mContext;

	protected BaseHolder(Context context, @NonNull View itemView) {
		super(itemView);
		mContext = context;
		mConvertView = itemView;
		mViews = new SparseArray<View>();
	}

	public  <T extends View> T getViewById(@IdRes int id) {
		View view = mViews.get(id);
		if (null == view) {
			view = mConvertView.findViewById(id);
			mViews.put(id, view);
		}
		return (T) view;
	}

	public BaseHolder setText(@IdRes int id, String content) {
		TextView textView = getViewById(id);
		textView.setText(content);
		return this;
	}

	public BaseHolder setVisible(@IdRes int id, int visible) {
		getViewById(id).setVisibility(visible);
		return this;
	}


}
